/*
 * Toedo
 * Copyright (C) 2009-2010 J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package org.toedo.gui.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.swt.widgets.Shell;
import org.toedo.controllers.DataController;
import org.toedo.gui.translations.Messages;
import org.toedo.logging.Log;
import org.toedo.model.Tag;
import org.toedo.model.validators.TagNameValidator;
import org.toedo.utils.Constants;

public class NewTagAction extends Action {

	private Shell mShell;
	
	public NewTagAction(Shell shell) {
		mShell = shell;
	}
	
	public void run() {
		InputDialog dialog = new InputDialog(mShell, Messages.NewTagAction_Title, Messages.NewTagAction_Message, Constants.TAG_DEFAULT_NAME, new TagNameValidator());
		
		int result = dialog.open();
		String tagName = dialog.getValue();
		if ((result == Dialog.OK) &&
				(tagName != null) &&
				(!tagName.isEmpty())) {									
			Tag newTag = DataController.getInstance().getProject().addTag(tagName);
			
			Log.getInstance(NewTagAction.class).debug(String.format("Tag created: %s (%s)", newTag.getName(), newTag.getId())); //$NON-NLS-1$
		}
	}
	
}
